from app import db, User, app

def init_db():
    with app.app_context():
        db.drop_all()
        db.create_all()

        # 添加教师用户
        teacher = User(name='Teacher', role='teacher')
        teacher.set_password('12345')  # 请更改为安全的密码

        # 添加学生用户
        student1 = User(name='HJJ', role='student')
        student1.set_password('123')
        student2 = User(name='FWB', role='student')
        student2.set_password('321')

        db.session.add(teacher)
        db.session.add(student1)
        db.session.add(student2)
        db.session.commit()

        print('数据库初始化完成，并添加了教师和学生用户。')

if __name__ == '__main__':
    init_db()